package me.ereach.collections;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

public class CollectionsDemo {
    public static void show() {
        Collection<String> collection = new ArrayList<>();

        Collections.addAll(collection, "a", "b", "c");

        for (var x : collection)
            System.out.println(x);

        System.out.println("---println(collection)---");
        System.out.println(collection);

        System.out.println("---println(collection.size())---");
        System.out.println(collection.size());  // show the size of the collection

        System.out.println("---objArray -> collection.toArray()---");
        var objArray = collection.toArray();
        System.out.println(objArray);

        System.out.println("---strArray -> collection.toArray(new String[3])---");
        var strArray = collection.toArray(new String[0]);
        System.out.println(strArray);

        System.out.println("---for each iterator---");
        for (var x : strArray)
            System.out.println(x);

        System.out.println("---remove operation---");
        collection.remove("a");     // remove "a" from the collection
        System.out.println(collection);

        System.out.println("---contains operation---");
        System.out.println(collection.contains("c"));   // if collection contains "c"

        System.out.println("---clear operation---");
        collection.clear();     // clear the collection
        System.out.println(collection);

        System.out.println("---isEmpty testing---");
        System.out.println(collection.isEmpty());   // if collection is empty

        System.out.println("---collection compare---");
        Collection<String> first = new ArrayList<>();
        Collections.addAll(first, "a", "b", "c");

        Collection<String> second = new ArrayList<>();
        Collections.addAll(second, "a", "b", "c");
        System.out.println(first == second);
        System.out.println(first.equals(second));

    }
}
